#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while (x);
	while (__top) putchar(__stk[__top--] + '0');
}

const int mod = 998244353;

void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }

void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }

int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }

bool stmer;

const int N = 1e5 + 10;

int n;

vector<int> e[N];
multiset<pair<int, int>> s[N];

void dfs(int x, int fa) {
    for (int v : e[x]) if (v ^ fa) {
        dfs(v, x);
        if (s[x].size() < s[v].size()) swap(s[x], s[v]);
        s[x].insert(s[v].begin(), s[v].end());
    }
    int v = 0, op = 0;
    if (s[x].size() > 1) {
        auto it = s[x].end(); it--;
        v += it -> first, op |= it -> second;
        s[x].erase(it), it = s[x].end(), it--;
        v += it -> first, op |= it -> second, s[x].erase(it);
        if (s[x].empty()) op = 0;
        s[x].insert({ v + 1, op });
    }
    else {
        if (!s[x].empty()) {
            auto it = s[x].begin();
            v = it -> first, s[x].erase(it), s[x].insert({ v, 1 });
        }
        s[x].insert({ 1, 0 });
    }
}

bool edmer;
signed main() {
	freopen("bird.in", "r", stdin);
	freopen("bird.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
	
    n = read();
    for (int i = 1; i < n; i++) {
        int u = read(), v = read();
        e[u].push_back(v), e[v].push_back(u);
    }

    dfs(1, 0);

    auto it = s[1].end(); it--;
    write(it -> first + it -> second);

    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
	return 0;
} 